package cn.coisini.controller.v1;

import cn.coisini.api.admin.AsyncOperLogControllerApi;
import cn.coisini.model.common.annotation.RedisAccessLimit;
import cn.coisini.model.common.dtos.Result;
import cn.coisini.model.common.enums.ResultEnum;
import cn.coisini.model.common.log.annotation.Log;
import cn.coisini.model.common.log.enums.BusinessType;
import cn.coisini.model.common.log.service.AsyncOperLogService;
import cn.coisini.model.pojo.AsyncOperLog;
import cn.coisini.model.vo.AsyncOperLogQueryVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author xiangshaw
 * Description: 操作日志
 */
@RestController
@RequiredArgsConstructor
public class AsyncOperLogController implements AsyncOperLogControllerApi {

    private final AsyncOperLogService operLogService;

    // 条件分页查询
    @Override
    @RedisAccessLimit(seconds = 60, maxCount = 30)
    public Result<Page<AsyncOperLog>> pagingQuery(AsyncOperLogQueryVo asyncOperLogQueryVo) {
        return operLogService.pagingQuery(asyncOperLogQueryVo);
    }

    // 根据id查询操作日志
    @Override
    @RedisAccessLimit(seconds = 60, maxCount = 30)
    public Result<AsyncOperLog> getOpenLog(String id) {
        return operLogService.get(id);
    }

    // 根据id删除操作日志
    @Override
    @RedisAccessLimit(seconds = 60, maxCount = 30)
    @Log(title = "操作日志管理",businessType = BusinessType.DELETE)
    public Result<ResultEnum> removeOperLogById(String id) {
        return operLogService.removeOperLogById(id);
    }

    // 批量删除操作日志
    @Override
    @RedisAccessLimit(seconds = 60, maxCount = 30)
    @Log(title = "操作日志管理",businessType = BusinessType.BATCH_REMOVE)
    public Result<ResultEnum> batchRemove(List<String> ids) {
        return operLogService.batchRemove(ids);
    }
}
